package com.hengxinyongli.iam.configuration;

import com.hengxinyongli.iam.web.filter.IamLocalFilter;
import com.hengxinyongli.iam.web.filter.IamRemoteFilter;
import com.hengxinyongli.iam.web.filter.RequestAssignment;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author magic
 * @date 2018/9/27/027 16:43
 * @version 1.0
 * Description IamAutoConfiguration
 */
@Configuration
public class IamAutoConfiguration {

    @Bean
    @ConditionalOnMissingClass("com.hengxinyongli.iam.remote.IamServiceImpl")
    @ConditionalOnProperty(value = "iam.enable",havingValue = "true",matchIfMissing = true)
    public IamRemoteFilter iamRemoteFilter(){
        return new IamRemoteFilter();
    }

    @Bean
    @ConditionalOnClass(name = "com.hengxinyongli.iam.remote.IamServiceImpl")
    @ConditionalOnProperty(value = "iam.enable",havingValue = "true",matchIfMissing = true)
    public IamLocalFilter iamFilter(){
        return new IamLocalFilter();
    }

    @Bean
    public RequestAssignment requestAssignment(){
        RequestAssignment requestAssignment = new RequestAssignment();
        return requestAssignment;
    }

}
